package cn.mothin.dao;
 
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import cn.mothin.entity.OperationLink;
import cn.mothin.frame.core.base.BaseDao;

@Repository ("4a69bdf0-a239-4372-80c2-61bcb7de6591")
public class OperationLinkDao extends BaseDao<OperationLink>{ 
	/**
	 * 根据提供的action查询相关联操作
	 * 
	 * @param action
	 * @return
	 */
	public List<Map<String, Object>> queryOperations(String action,boolean rowOperation) {
		String sql = "SELECT f.id,f.ico,f.name,f.action,o.ordinal,o.subOrdinal FROM operation_link o LEFT JOIN function_item f ON o.functionItemId=f.id WHERE o.action=? AND rowOperation=? AND subOrdinal=0 ORDER BY o.ordinal";
		return sqlHelper.queryForList(sql, action,rowOperation);
	}
	
	/**
	 * 根据提供的action查询相关联操作
	 * 
	 * @param action
	 * @return
	 */
	public List<Map<String, Object>> queryOperations(String action,boolean rowOperation,int ordinal) {
		String sql = "SELECT f.id,f.ico,f.name,f.action,o.ordinal,o.subOrdinal FROM operation_link o LEFT JOIN function_item f ON o.functionItemId=f.id WHERE o.action=? AND rowOperation=? AND o.ordinal=? AND o.subOrdinal>0 ORDER BY o.subOrdinal";
		return sqlHelper.queryForList(sql, action,rowOperation,ordinal);
	}
	
	/**
	 * 根据action，ordinal查询子级操作
	 * 
	 * @param action
	 * @param ordinal
	 * @return
	 */
	public List<Map<String,Object>> queryChildOperations(String action,int ordinal) {
		String sql = "SELECT f.id,f.ico,f.name,f.action,o.ordinal,o.subOrdinal FROM operation_link o " +
				"LEFT JOIN function_item f ON o.functionItemId=f.id " +
				"WHERE o.action=? AND o.ordinal = ? AND subOrdinal > 0  ORDER BY o.ordinal ";
		return sqlHelper.queryForList(sql, action, ordinal);
		
	}
}
